package com.agriculture.competition.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.agriculture.competition.domain.JaCompetitionSolution;
import com.agriculture.competition.service.IJaCompetitionSolutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.agriculture.common.log.annotation.Log;
import com.agriculture.common.log.enums.BusinessType;
import com.agriculture.common.security.annotation.RequiresPermissions;
import com.agriculture.common.core.web.controller.BaseController;
import com.agriculture.common.core.web.domain.AjaxResult;
import com.agriculture.common.core.utils.poi.ExcelUtil;
import com.agriculture.common.core.web.page.TableDataInfo;

/**
 * 解决方案Controller
 * 
 * @author agriculture
 * @date 2024-11-12
 */
@RestController
@RequestMapping("/solution")
public class JaCompetitionSolutionController extends BaseController
{
    @Autowired
    private IJaCompetitionSolutionService jaCompetitionSolutionService;

    /**
     * 查询解决方案列表
     */
    @RequiresPermissions("competition:solution:list")
    @GetMapping("/list")
    public TableDataInfo list(JaCompetitionSolution jaCompetitionSolution)
    {
        startPage();
        List<JaCompetitionSolution> list = jaCompetitionSolutionService.selectJaCompetitionSolutionList(jaCompetitionSolution);
        return getDataTable(list);
    }

    /**
     * 导出解决方案列表
     */
    @RequiresPermissions("competition:solution:export")
    @Log(title = "解决方案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JaCompetitionSolution jaCompetitionSolution)
    {
        List<JaCompetitionSolution> list = jaCompetitionSolutionService.selectJaCompetitionSolutionList(jaCompetitionSolution);
        ExcelUtil<JaCompetitionSolution> util = new ExcelUtil<JaCompetitionSolution>(JaCompetitionSolution.class);
        util.exportExcel(response, list, "解决方案数据");
    }

    /**
     * 获取解决方案详细信息
     */
    @RequiresPermissions("competition:solution:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jaCompetitionSolutionService.selectJaCompetitionSolutionById(id));
    }

    /**
     * 新增解决方案
     */
    @RequiresPermissions("competition:solution:add")
    @Log(title = "解决方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JaCompetitionSolution jaCompetitionSolution)
    {
        return toAjax(jaCompetitionSolutionService.insertJaCompetitionSolution(jaCompetitionSolution));
    }

    /**
     * 修改解决方案
     */
    @RequiresPermissions("competition:solution:edit")
    @Log(title = "解决方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JaCompetitionSolution jaCompetitionSolution)
    {
        return toAjax(jaCompetitionSolutionService.updateJaCompetitionSolution(jaCompetitionSolution));
    }

    /**
     * 删除解决方案
     */
    @RequiresPermissions("competition:solution:remove")
    @Log(title = "解决方案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jaCompetitionSolutionService.deleteJaCompetitionSolutionByIds(ids));
    }
}
